﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ParsecParser
{
    [Serializable]
    public class CombatLogParticipant : CombatLogEntity
    {
        public long UniqueId { get; set; }
        public bool IsThisPlayer { get; set; }
        public bool IsPlayer { get; set; }
        public bool IsEnemy { get; set; }
        public bool IsPlayerCompanion { get; set; }
        public string CompanionOwner { get; set; }
        public long TotalThreat { get; set; }
        public long TotalDamage { get; set; }
        public CombatLogParticipant() :base()
        {
        }
        public CombatLogParticipant(string name, long entityId, long uniqueId, bool isPlayer)
            : base(name, entityId)
        {
            UniqueId = uniqueId;
            IsPlayer = isPlayer;
        }
        public void SetIsThisPlayer(string charName)
        {
            this.IsThisPlayer = this.IsPlayer && this.DisplayName == charName;
        }
        public override string ToString()
        {
            if (IsPlayer)
                return DisplayName;
            else if (!string.IsNullOrEmpty(DisplayName + EntityId.ToString() + UniqueId.ToString()))
                return DisplayName + (IsPlayerCompanion ? " (" + CompanionOwner + ")" : "") + " (" + EntityId.ToString() + ":" + UniqueId.ToString() + ")";
            else
                return "";
        }
        public string DisplayNameWithOwner
        {
            get
            {
                return DisplayName + (IsPlayerCompanion ? " (" + CompanionOwner + ")" : "");
            }
        }
        public string GetUniqueKey()
        {
            if (IsPlayer && !IsPlayerCompanion)
                return DisplayName;
            else if (IsPlayerCompanion)
                return EntityId + CompanionOwner;
            return UniqueId.ToString();
        }
        //public int CompareTo(CombatLogParticipant c)
        //{
        //    if (IsPlayer && !IsPlayerCompanion)
        //    {
        //        if (!c.IsPlayer)
        //            return 1;
        //        else if (c.DisplayName == DisplayName)
        //            return 0;
        //        else
        //            return 1;
        //    }
        //    else if (IsPlayerCompanion)
        //    {
        //        if (!c.IsPlayerCompanion)
        //            return 1;
        //        else if (c.EntityId == EntityId && c.CompanionOwner == CompanionOwner)
        //            return 0;
        //        else
        //            return 1;
        //    }
        //    else if (c.UniqueId == UniqueId)
        //        return 0;
        //    else
        //        return 1;
        //}
        public int CompareTo(CombatLogParticipant c)
        {
            return GetUniqueKey().CompareTo(c.GetUniqueKey());
        }
        
        public const string EmptyParticipantName = "Someone";
    }
}
